﻿using System;
using System.Drawing;

namespace NetCoreCMS.Common
{
    public class CombinImg
    {
        /// <summary>
        /// 两种图片合并 
        /// //二维码宽130*130，x:100,y:786,字140*19，x:251,y:823,字72*18,x:355,y:864
        /// </summary>
        /// <param name="sourceImg">背景图片</param>
        /// <param name="img">前图片</param>
        public static Image CombinImage(string sourceImg, Image img, string topZi,string endZi, Image wximg)
        {
            Image imgBack = System.Drawing.Image.FromFile(sourceImg);     //相框图片  
            //Image img = System.Drawing.Image.FromFile(destImg);        //照片图片


            //从指定的System.Drawing.Image创建新的System.Drawing.Graphics        
            Graphics g = Graphics.FromImage(imgBack);

            g.DrawImage(imgBack, 0, 0, g.VisibleClipBounds.Width, g.VisibleClipBounds.Height);      // g.DrawImage(imgBack, 0, 0, 相框宽, 相框高); 
            //g.FillRectangle(System.Drawing.Brushes.Black, 16, 16, (int)112 + 2, ((int)73 + 2));//相片四周刷一层黑色边框

            //if(wximg!=null)
            //{
            //    img = CombinQR(img, wximg);
            //}
            //g.DrawImage(img, 照片与相框的左边距, 照片与相框的上边距, 照片宽, 照片高);
            g.DrawImage(img, 100, 786, 130, 130);
            //在画上写字top
            g.DrawString(topZi, new Font("黑体", 40, FontStyle.Regular), Brushes.DimGray, new PointF(240, 803));
            g.DrawString(endZi, new Font("黑体", 20, FontStyle.Regular), Brushes.DimGray, new PointF(355, 860));
            GC.Collect();
            return imgBack;
        }
        public static Image CombinQR(Image imgBack, Image wx)
        {
            Graphics g = Graphics.FromImage(imgBack);
            g.DrawImage(imgBack, 0, 0, 280, 280);      // g.DrawImage(imgBack, 0, 0, 相框宽, 相框高); 
            //g.DrawImage(img, 照片与相框的左边距, 照片与相框的上边距, 照片宽, 照片高);
            g.DrawImage(wx, 90, 90, 60, 60);
            GC.Collect();
            return imgBack;
        }
    }
}
